<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
<script type="text/javascript" src="lib/zepto.min-1.2.0.js"></script>
<script type="text/javascript" src="lib/encrypt.js"></script>
<script type="text/javascript" src="lib/jsbn.js"></script>
<script type="text/javascript" src="lib/prng4.js"></script>
<script type="text/javascript" src="lib/rng.js"></script>
<script type="text/javascript" src="lib/rsa.js"></script>
<script type="text/javascript" src="lib/base64.js"></script>
<script type="text/javascript">
function SEND(url, data, header, fn){
	var xhr = new XMLHttpRequest();
	xhr.open('POST', url, true);
	xhr.addEventListener('load', function load(){
		this.removeEventListener('load', load);
		var result = xhr.response || xhr.responseText;
		if(typeof(result) == 'string'){
			try{
				result = JSON.parse(result);
			} catch(ex){ }
		}
		fn(result);
		xhr = null;
	});
	if(header){
		for(var p in header){
			xhr.setRequestHeader(p, header[p]);
		}
	}
	xhr.send(data || null);
};
function post(url, data, fn){
	var xhr = new XMLHttpRequest();
	xhr.open('POST', url, true);
	xhr.addEventListener('load', function load(){
		this.removeEventListener('load', load);
		fn(xhr.response || xhr.responseText);
		xhr = null;
	});
	xhr.responseType = 'json';
	xhr.send(data || null);
};
</script>
</head>
<body>

<input type="file">

<hr>

{"status":200,"message":"ok","cmd":{"NONE":0,"HELO":1,"AUTH":2,"CONF":3,"SHND":4,"UPLO":5,"DONE":6,"HELP":7,"UNKN":99}}
<pre></pre>


<script type="text/javascript">
var url = "http://localhost:51137/Default.aspx";
var url = "http://localhost:51137/api.aspx";

$('input[type="file"]').on('change', function(e){
	
	var file = this.files[0];
	var metaData = {
		size: file.size,
		name: file.name,
		type: file.type,
		lastModified: file.lastModified
	};
	var data = new FormData();
	data.append('session', '4d48c5ed506c6abcba1c5d5f84f9661051fac70a6bdd420ca5f1743dd484800e');
	data.append('uploadcmd', 4);

	var reader = new FileReader();
	reader.onload = function(){
		metaData.hash = encrypt.sha1(this.result);
		data.append('data', JSON.stringify(metaData));
		post(url, data, function(r){
			console.log(r)
		})
	};
	reader.readAsBinaryString(file);

	

	this.value = null;
});

var rsa_m = 'aa6efa10ca436173d9af82df8be8c6cc19a4564aef654b6cb0d6f8a90dafe7e0b29dd1642efa958e1c93f1afa594e43d190b5d2acdab18d794ca794c28cb93e163132d0c41da05566391f54c8508eef5b2094cb79fab53d1bbb9d501dda88c03ebfdd2453b5c9345592bc3cd90e0702fc191cc23e4833ceb75755216c414e021';

var rsa_e = "10001";
var rsa = new RSAKey();

rsa.setPublic(rsa_m, rsa_e);
var res = rsa.encrypt("123");


console.log(res);

// var data = new FormData();
// data.append('uploadcmd', 4);
// data.append('session', '4d48c5ed506c6abcba1c5d5f84f9661051fac70a6bdd420ca5f1743dd484800e');
// post(url, data, function(r){
// 	console.log(r)
// })

// SEND(url, JSON.stringify({
// 	size: 1024,
// 	type: 'text/json',
// 	lastModified: Date.now(),
// 	name: 'test.json',
// 	//hash: 'a4b9633c685d9665a970092a094f15a327877016'
// }), {
// 	'UPLOADCMD':4,
// 	'GUID': 'd5f3f4f87d574fad9a29a59830905d08'
// }, function(r){
// 	console.log(r);
// })

</script>

</body>
</html>